<?php
/**
 * Project:	BBCodeAdvanced
 * File:	class.DB.php
 *
 * @link http://code.google.com/u/kendertas/
 * @copyright 2009 KenderTas
 * @author Kender Tas <kendertas at gmail dot com>
 * @package classes
 * @version 1.0.0
 */

class DB	{

	function SQL_Open($SQLhost, $SQLuser, $SQLpassword, $SQLdatabase, $SQLpersistency = true)	{
		$this->SQLhost			= $SQLhost;
		$this->SQLuser			= $SQLuser;
		$this->SQLpassword		= $SQLpassword;
		$this->SQLdatabase		= $SQLdatabase;
		$this->SQLpersistency	= $SQLpersistency;

		//	connect
		if($this->SQLpersistency)	{
			$this->conn = @mysql_pconnect($this->SQLhost, $this->SQLuser, $this->SQLpassword);
		} else {
			$this->conn = @mysql_connect($this->SQLhost, $this->SQLuser, $this->SQLpassword);
		}
		if ($this->conn)	{
			//	select DB
			$SQLdbSelect = @mysql_select_db($this->SQLdatabase);
			if(!$SQLdbSelect)	{
				@mysql_close($this->conn);
				die("No DB Select.");
			} else {
				return $this->conn;
			}
		} else {
			die("Connection to SQL Server failed.\n<br>#".mysql_errno()."<br>\n".mysql_error());
		}
	}
	function SQL_Close($conn)	{
		if ($conn)
			@mysql_close($this->conn);
	}

	function SQL_Query($qry, $conn)	{
		if ($qry != "")	{
			$result = @mysql_query($qry, $conn);
		}
		if ($result)	{
			return $result;
		} else {
			trigger_error("Errore nell'esecuzione della query:{$qry}<br>DB error:" . mysql_errno($conn) . "," . mysql_error($conn), E_USER_ERROR);
		}
	}

	function SQL_NumRows($result)	{
		if ($result)	{
			return @mysql_num_rows($result);
		}
	}
	function SQL_FetchArray($result)	{
		if ($result)	{
			$row[$result] = @mysql_fetch_array($result);
			return $row[$result];
		}
	}
}
?>